package com.shengyo.model.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.shengyo.model.bean.Computer;
import com.shengyo.model.bean.Digital;
import com.shengyo.model.dao.IComputerDAO;


public class ComputerDAOImpl extends BaseDAOImpl implements IComputerDAO{

	@Override
	public void delete(Computer computer) {
		this.getHibernateTemplate().delete(computer);
	}

	@Override
	public Computer findByComputerUrl(String url) {
		return (Computer) this.getHibernateTemplate().load(Computer.class , url);
	}

	@Override
	public Computer findById(String id) {
		return (Computer) this.getHibernateTemplate().load(Computer.class, id);
	}

	@Override
	public List<?> findAll() {
		return this.getHibernateTemplate().find("from computer");
	}

	@SuppressWarnings("unchecked")
	public List<Digital> findAll(final int first, final int max) {
		return this.getHibernateTemplate().executeFind(new HibernateCallback(){

			public Computer doInHibernate(Session session)
					throws HibernateException, SQLException {
				return (Computer) session.createQuery("from computer").setFirstResult(first).setMaxResults(max).list();
			}
			
		});
	}

	@Override
	public Object findById(int id) {
		return null;
	}

}
